﻿<script type="text/javascript" >
    function explode( delimiter, string, limit ) {
        var emptyArray = { 0: '' };
    
        // third argument is not required
        if ( arguments.length < 2
            || typeof arguments[0] == 'undefined'
            || typeof arguments[1] == 'undefined' )
        {
            return null;
        }
 
        if ( delimiter === ''
            || delimiter === false
            || delimiter === null )
        {
            return false;
        }
 
        if ( typeof delimiter == 'function'
            || typeof delimiter == 'object'
            || typeof string == 'function'
            || typeof string == 'object' )
        {
            return emptyArray;
        }
 
        if ( delimiter === true ) {
            delimiter = '1';
        }
    
        if (!limit) {
            return string.toString().split(delimiter.toString());
        } else {
            // support for limit argument
            var splitted = string.toString().split(delimiter.toString());
            var partA = splitted.splice(0, limit - 1);
            var partB = splitted.join(delimiter.toString());
            partA.push(partB);
            return partA;
        }
    }// }}}
    var otherTitleFirst ='other_title_textbox_';
    var otherLinkFirst ='other_link_to_price_list_';
    var otherUniformFirst = 'other_uniform_price_';
    var slashChar = '| ';
    var slash = addElementHTML('font','','','#333333',slashChar ) ;
    var textPTPL ='{JS_TEXT.textPTPL}';
    var textS1 ='{JS_TEXT.textS1}';
    var textS2_1 ='{JS_TEXT.textS2_1}';
    var textS2_2 ='{JS_TEXT.textS2_2}';
    function setInitializeAddNew(){
        var obj = document.getElementById("product_id");
        obj.setAttribute('readonly',false);
    }
    function setInitializeEdit(){
        var obj= document.getElementById("product_id");
        obj.setAttribute('readonly',true);
    }
    function save_edit_product(){
        // The first step - check empty text fill
        //if(!checkEmptyForm("frmNewProduct"))
        //	return false;
        getAllValueOfRadioAndCheckboxArray("frmNewProduct");
        var frm =	document.getElementById("frmNewProduct");

        //var text = tinyMCE.get('product_description').getContent();
        //frm.product_description.value = text;
		
        /*	product_description_normal = document.getElementById("product_description_normal").value;
        if(parseInt(product_description_normal)==0)
                {
                        frm.product_description. = frm.product_description_html_tag.value;
                        var desc = tinyMCE.get('product_description').getContent();
                        alert(frm.product_description_html_tag.value);
                        alert(frm.product_description.value);
                        frm.product_description.value = desc;
			
                }*/
        // get mobile description version
        var val = getCheckedValue(frm.product_description_swich);
        if(val == 1){
            var text_2 = tinyMCE.get('product_description_on_mobile').getContent();
            frm.product_description_on_mobile.value = text_2;
            frm.product_description_on_mobile.value = frm.product_description.value;
        }
        frm.submit();
    }
    var preE5;
    function HighLightTR_Product_main(el,pid,pname,id_label){
        var backColor='#E7E7E7';
        var textColor='#00CC00';
        var selected=document.getElementById('id_first_line_product').value;
        var first_row=document.getElementById(selected);
        if(typeof(first_row)!='undefined'){
            first_row.style.color="#333333";
        }
        if(typeof(preE5)!='undefined'){
            preE5.bgColor=orgBColor;
            preE5.style.color=orgTColor;
        }
        document.getElementById(id_label).innerHTML = pname;
        orgBColor = el.bgColor;
        orgTColor = el.style.color;
        el.bgColor=backColor;
        el.style.color=textColor;
        preE5 = el;
        ajax_load_picture_main(pid);

    }
    function ajax_load_picture_main(pid){
        display("Loading   ",'ajax_loading');
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" )
        {
            var myQuery = '&pid='+pid;
            orderPost( oXMLHttp, "?sMod=invoice&CaseAction=load_piture_product&ismain=1", myQuery, HTTPShow_product_picture, true );
        }
    }

    function change_tab(tab_enable,tab_disable){
        var tabEnable 	=	document.getElementById(tab_enable);
        var tabDisable 		=	document.getElementById(tab_disable);
        tabDisable.style.display= 'none';
        tabEnable.style.display= '';
	
    }
    function enable_div(div_id){
        var div=	document.getElementById(div_id);
	
    }

    function convert_jsa_to_phpa(jsa){
        var new_a = new Array();
        var string_arr='';
        for(var j=0; j<jsa.length; j++ )
        {
            new_a.push(jsa[j].toString());
        }
        for(var j=0; j<new_a.length; j++ ){
            if(j==0) string_arr= new_a[j]; else
                string_arr = string_arr+"139211"+new_a[j];
        }
        return string_arr;
    }


    function edit_mode(inven_no,pid,cosref,iscombo){
        var serial_invoice = document.getElementById('serial_invoice').value;
        if( (serial_invoice.length == 0) || (serial_invoice == '') )
            alert("Not Found serial of this invoice, can not continues process!\nReset System, please.");
        else
            currentWindow = window.open('?sMod=invoice&CaseAction=add_product_to_invoice_layer&editMode=1&pid='+pid+"&serial_invoice="+serial_invoice+"&costreference="+cosref+"&serial="+inven_no+"&iscombo="+iscombo, "Choose exist invoice","location=0,status=0,scrollbars=0, directories =0, menubar=0,toolbar=0, resizable=0,width=800,height=500");
        currentWindow.window.moveTo(100,100);
        currentWindow.window.focus();
        //OpenWindow(,'','toolbar=no, menubar=no, scrollbars=no, resizable=no,',1024,728, true);
    }

    function check_enter_key(e,obj,frmID){
        var ASCII_Code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;	
        var char = eval("String.fromCharCode("+ASCII_Code+")") ;
        if (ASCII_Code != 13)
        {
            // nothing to do
        }else {
            executeSearchProductList("0",frmID);
        }
                    
    }
    function set_value_to_txtbox(source, destination){
        var obj_dest= document.getElementById(destination);
        return obj_dest.value = source.value;
    }
	


    function reFresh_opner_page()
    {
        if(document.getElementById('check_submit_exits').value==0)
        {
            window.opener.location.href = "?sMod=invoice&CaseAction=''";
        }
        else
            window.opener.location.href = "?sMod=invoice";
        window.opener.focus();
        window.close();
    }
		
    function focus_invoice_no(){
        var obj=document.NEW_INVOICE_FRM.focus_invoice_no;
        obj.focus()
    }
    //**************************************************************************//

    var preEl ;
    var orgBColor;
    var orgTColor;
    function HighLightTR(el,serial){
        var backColor='#E7E7E7';
        var textColor='#00CC00';
        var selected=document.getElementById('first_row_id').value;
        var first_row=document.getElementById(selected);
        if(typeof(first_row)!='undefined'){
            first_row.style.color="#333333";
        }
		
        if(typeof(preEl)!='undefined'){
            preEl.bgColor=orgBColor;
            preEl.style.color=orgTColor;
        }
        orgBColor = el.bgColor;
        orgTColor = el.style.color;
        el.bgColor=backColor;
        el.style.color=textColor;
        preEl = el;

        var invoice_serial_selected = 	document.getElementById('invoice_serial_selected');
        invoice_serial_selected.value = serial;

    }

    function check_error_add_new_invoice(frm_name){
        var frm = document.getElementById(frm_name);
        if(frm.invoicedate_new.value.length==0)
        {
            display("Please Select invoice date!",'invoicedate_error');
            frm.button2222.focus();
            return false;
        }
        if(frm.invoicenum.value.length==0)
        {
            display("Please Enter invoice number!", 'invoicenum_error');
            frm.invoicenum.focus();
            return false;
        }
        if(frm.vendorreference_display.value.length==0)
        {
            display("Please Enter vender!",'vendorreference_error');
            frm.vendorreference_display.focus();
            return false;
        }
        send_vender();
		
    }
		
		

    function check_Number(strNumber)
    {
        var	number ="0123456789.-";
        var vt,kt,l,result;
        var f_dot_pos,l_dot_pos;
        result= true;
        for(i=0;i<8;i++)
        {
            kt= strNumber.charAt(i);
            vt=number.indexOf(kt);
            if(vt==-1){
                result=false;
                break;
            }
		
        }// end for
        /*	if(result==true){
                           f_dot_pos = strNumber.indexOf('.');
                           l_dot_pos = strNumber.lastIndexOf('.');
                           if(f_dot_pos ==0) ; result= false;
                           if(f_dot_pos!=l_dot_pos) result= false;
                        }
                        alert(f_dot_pos);
                        alert(l_dot_pos);
                        alert(result);
        if(result==true){
                         var  f_minus_sign= strNumber.indexOf('-');
                           if(f_minus_sign!= -1 || f_minus_sign!=-0) result= false;
                        }	*/
        return result;
    }

    var preE2 ;
    function HighLightTR_inventory(el,serial){
        var backColor='#E7E7E7';
        var textColor='#00CC00';
        var selected=document.getElementById('first_row_id').value;
        var first_row=document.getElementById(selected);
        if(typeof(first_row)!='undefined'){
            first_row.style.color="#333333";
        }
		
        if(typeof(preE2)!='undefined'){
            preE2.bgColor=orgBColor;
            preE2.style.color=orgTColor;
        }
        orgBColor = el.bgColor;
        orgTColor = el.style.color;
        el.bgColor=backColor;
        el.style.color=textColor;
        preE2 = el;

    }
    var preE3 ;
    function HighLightTR_CRV(el){
        var backColor='#E7E7E7';
        var textColor='#00CC00';
        var selected=document.getElementById('first_row_id_crv').value;
        var first_row=document.getElementById(selected);
        if(typeof(first_row)!='undefined'){
            first_row.style.color="#333333";
        }
		
        if(typeof(preE3)!='undefined'){
            preE3.bgColor=orgBColor;
            preE3.style.color=orgTColor;
        }
        orgBColor = el.bgColor;
        orgTColor = el.style.color;
        el.bgColor=backColor;
        el.style.color=textColor;
        preE3 = el;

    }
    var preE4;
    function HighLightTR_Product(el,pid,pname,id_label){
        var backColor='#E7E7E7';
        var textColor='#00CC00';
        var selected=document.getElementById('id_first_line_product').value;
        var first_row=document.getElementById(selected);
        if(typeof(first_row)!='undefined'){
            first_row.style.color="#333333";
        }
        if(typeof(preE4)!='undefined'){
            preE4.bgColor=orgBColor;
            preE4.style.color=orgTColor;
        }
        document.getElementById(id_label).innerHTML = pname;
        orgBColor = el.bgColor;
        orgTColor = el.style.color;
        el.bgColor=backColor;
        el.style.color=textColor;
        preE4 = el;
        ajax_load_picture(pid);

    }
    function ajax_load_picture(pid){
        display("Loading   ",'ajax_loading');
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" )
        {
            var myQuery = '&pid='+pid;
            orderPost( oXMLHttp, "?sMod=invoice&CaseAction=load_piture_product", myQuery, HTTPShow_product_picture, true );
        }
    }
    function HTTPShow_product_picture()
    {
        if ( typeof(oXMLHttp)==='undefined' )
            return;
							  
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                { if ( oJson['BODY']['RES'] != '' )
                        document.getElementById('piture_product_search').innerHTML = oJson['BODY']['RES'];
                }
            }
            display("",'ajax_loading');
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
                        
    }
    function numbersonly(e,obj, length)
    {
        var maxlength=length
        if (obj.value.length>maxlength)
            obj.value=obj.value.substring(0, maxlength);
		
        var unicode=e.charCode? e.charCode : e.keyCode;
        if ((unicode!=8)&&(unicode!=9)&&(unicode!=37)&&(unicode!=38)&&(unicode!=39)&&(unicode!=40)&&(unicode!=46))
        {
            if (unicode<48||unicode>57) //if not a number
                return false; //disable key press
        }
    }

    function Trim(sString) {
        while (sString.substring(0,1) == " ")
        {
            sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == " ")
        {
            sString = sString.substring(0,sString.length-1);
        }


        return sString;
    }
    function round(number,X) {//
        // rounds number to X decimal places, defaults to 2
        X = (!X ? 2 : X);
        return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
    }
    function php_serialize(obj)  {
        var string = '';

        if (typeof(obj) == 'object') {
            if (obj instanceof Array) {
                string = 'a:';
                tmpstring = '';
                count = 0;
                for (var key in obj) {
                    tmpstring += php_serialize(key);
                    tmpstring += php_serialize(obj[key]);
                    count++;
                }
                string += count + ':{';
                string += tmpstring;
                string += '}';
            } else if (obj instanceof Object) {
                classname = obj.toString();

                if (classname == '[object Object]') {
                    classname = 'StdClass';
                }

                string = 'O:' + classname.length + ':"' + classname + '":';
                tmpstring = '';
                count = 0;
                for (var key in obj) {
                    tmpstring += php_serialize(key);
                    if (obj[key]) {
                        tmpstring += php_serialize(obj[key]);
                    } else {
                        tmpstring += php_serialize('');
                    }
                    count++;
                }
                string += count + ':{' + tmpstring + '}';
            }
        } else {
            switch (typeof(obj)) {
                case 'number':
                    if (obj - Math.floor(obj) != 0) {
                        string += 'd:' + obj + ';';
                    } else {
                        string += 'i:' + obj + ';';
                    }
                    break;
                case 'string':
                    string += 's:' + obj.length + ':"' + obj + '";';
                    break;
                case 'boolean':
                    if (obj) {
                        string += 'b:1;';
                    } else {
                        string += 'b:0;';
                    }
                    break;
            }
        }

        return string;
    }





    var preEl5 ;
    function HighLightTR_Iscombo_Row(el,serial,pid){
        var backColor='#E7E7E7';
        var textColor='#00CC00';
        var selected=document.getElementById('id_first_iscombo_item').value;
        var first_row=document.getElementById("tr_"+selected);
        if(typeof(first_row)!='undefined'){
            first_row.style.color="#333333";
        }
		
        if(typeof(preEl5)!='undefined'){
            preEl5.bgColor=orgBColor;
            preEl5.style.color=orgTColor;
        }
			 
        orgBColor = el.bgColor;
        orgTColor = el.style.color;
        el.bgColor=backColor;
        el.style.color=textColor;
        preEl5 = el;
		  
        ajax_load_picture(pid);
    }
    function check_error_save_list_product(){
        var buy_txt 				= document.getElementById('buy_txt');
        var case_txt 				= document.getElementById('case_txt') ;
        var disccount_txt 			= document.getElementById('disccount_txt');
        var pack_txt			 	= document.getElementById('pack_txt');

        if(buy_txt.value.length==0)
        {
            display("Not allow empty",'empty_buy_txt');
            buy_txt.focus();
            return false;
        }
        if(case_txt.value.length==0)
        {
            display("Not allow empty",'empty_case_txt');
            case_txt.focus();
            return false;
        }
							
        if(disccount_txt.value.length==0)
        {
            display("Not allow empty",'empty_disccount_txt');
            disccount_txt.focus();
            return false;
        }
							
        if(pack_txt.value.length==0)
        {
            display("Not allow empty",'empty_pack_txt');
            pack_txt.focus();
            return false;
        }
						
														
        return true;
    }
    function enable_this_module(div_id){
        document.getElementById(div_id).style.display='';
        popup.open(div_id);
	
    }
    function set_undefined_window(){
        window.opener.currentWindow='undefined';
    }

    function disable_other_button(){
        //document.getElementById('ok_new_crv_btt').
        document.getElementById('cancel_new_adjustment').disabled='disabled';
        document.getElementById('ok_new_adjustment').disabled='disabled';
        document.getElementById('delete_this_adjustment').disabled='disabled';
    }
	
    function enableOrDisableDivTag(div_id) {
        if(document.getElementById(div_id))
            toggleDisabled( document.getElementById(div_id) );
    }
    
    function toggleDisabled(el) {
        try {
            el.disabled == el.disabled ? false : true;
        }
        catch(E){
        }
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                toggleDisabled(el.childNodes[x]);
            }
        }
    }
    function save_new_product_defaul(){   //Edit by Nam
        //alert("defaul");
        getAllValueOfRadioAndCheckboxArray("frmNewProduct");
        var frm =	document.getElementById("frmNewProduct");
		if(frm.product_price.value==""){
		 alert("開始価格を入力して下さい");
		 frm.product_price.focus();
		 return false;
		}
        frm.submit();
    }
    
    function save_new_product(){
        // The first step - check empty text fill
        //if(!checkEmptyForm("frmNewProduct"))
        //	return false;
        // alert("submit test");
        getAllValueOfRadioAndCheckboxArray("frmNewProduct");
        var frm =	document.getElementById("frmNewProduct");
        // prepare for send data,

        /*var text = tinyMCE.get('product_description').getContent();
                frm.product_description.value = text;	*/
        /*product_description_normal = document.getElementById("product_description_normal").value;
        if(parseInt(product_description_normal)==0)*/
        //frm.product_description.value = frm.product_description_html_tag.value;
		
        // get mobile description version
        var val = getCheckedValue(frm.product_description_swich);
        if(val == 1){
            var text_2 = tinyMCE.get('product_description_on_mobile').getContent();
            frm.product_description_on_mobile.value = text_2;
        }
	
        //BY MINHHTN
        var text = tinyMCE.get('product_explanation').getContent();
        frm.product_explanation.value = text;
	
        var text_1 = tinyMCE.get('product_rank').getContent();
        frm.product_rank.value = text_1;
	
        var text_2 = tinyMCE.get('product_note').getContent();
        frm.product_note.value = text_2;
	
        //var check_negotion=document.getElementById('product_have_to_negotiate_discount');
        //CHECK NAME
        var product_title=document.getElementById('product_title');
        var product_store=document.getElementById('product_store');
        /*
        var product_key1=document.getElementById('product_key1');
        var product_key2=document.getElementById('product_key2');
        var product_key3=document.getElementById('product_key3');
        var product_key4=document.getElementById('product_key4');
        var product_key5=document.getElementById('product_key5');
         */
        if(product_title.value=='')
        {
            alert("{TEXT.input_product_title}");
            product_title.focus();
            return false;
        }
        if(product_title.value.length>25)
        {
            alert("The max length of product title is 25 charactors");
            product_title.focus();
            return false;
        }
        if(product_store.value.length>3)
        {
            alert("The max length of store name is 3 charactors");
            product_store.focus();
            return false;
        }
        /*
        if(product_key1.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key1.focus();
                return false;
        }
        if(product_key2.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key2.focus();
                return false;
        }
        if(product_key3.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key3.focus();
                return false;
        }
        if(product_key4.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key4.focus();
                return false;
        }
        if(product_key5.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key5.focus();
                return false;
        }
         */
        //
        var obj_price_start=document.getElementById('product_prices_start');
        if(obj_price_start.value=='')
        {
            alert("{TEXT.input_price_start}");
            obj_price_start.focus();
            return false;
        }
        /*
        if(check_negotion.checked==true)
        {
		
                var price_sum=document.getElementById('product_price_fastener').value;
                var price_start=document.getElementById('product_prices_start').value;
                if(price_sum!=price_start)
                {
                        alert("{TEXT.price_negotion}");
                        check_negotion.focus();
                        return false;
                }
        }
         */
	
	
        frm.submit();
    }
    function save_new_product1(){
        // The first step - check empty text fill
        //if(!checkEmptyForm("frmNewProduct"))
        //	return false;
        // alert("submit test");
        getAllValueOfRadioAndCheckboxArray("frmNewProduct");
        var frm =	document.getElementById("frmNewProduct");
        // prepare for send data,

        /*var text = tinyMCE.get('product_description').getContent();
                frm.product_description.value = text;	*/
        /*product_description_normal = document.getElementById("product_description_normal").value;
        if(parseInt(product_description_normal)==0)*/
        //frm.product_description.value = frm.product_description_html_tag.value;
		
        // get mobile description version
        var val = getCheckedValue(frm.product_description_swich);
        if(val == 1){
            var text_2 = tinyMCE.get('product_description_on_mobile').getContent();
            frm.product_description_on_mobile.value = text_2;
        }
	
        //BY MINHHTN
        var text = tinyMCE.get('product_explanation').getContent();
        frm.product_explanation.value = text;
	
        var text_1 = tinyMCE.get('product_rank').getContent();
        frm.product_rank.value = text_1;
	
        var text_2 = tinyMCE.get('product_note').getContent();
        frm.product_note.value = text_2;
	
        //var check_negotion=document.getElementById('product_have_to_negotiate_discount');
        //CHECK NAME
        var product_title=document.getElementById('product_title');
        var product_store=document.getElementById('product_store');
        /*
        var product_key1=document.getElementById('product_key1');
        var product_key2=document.getElementById('product_key2');
        var product_key3=document.getElementById('product_key3');
        var product_key4=document.getElementById('product_key4');
        var product_key5=document.getElementById('product_key5');
         */
        /*if(product_title.value=='')
        {
            alert("{TEXT.input_product_title}");
            product_title.focus();
            return false;
        }
        if(product_title.value.length>19)
        {
            alert("The max length of product title is 19 charactors");
            product_title.focus();
            return false;
        }
        if(product_store.value.length>3)
        {
            alert("The max length of store name is 3 charactors");
            product_store.focus();
            return false;
        }*/
        /*
        if(product_key1.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key1.focus();
                return false;
        }
        if(product_key2.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key2.focus();
                return false;
        }
        if(product_key3.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key3.focus();
                return false;
        }
        if(product_key4.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key4.focus();
                return false;
        }
        if(product_key5.value.length>3)
        {
                alert("The max length of store name is 3 charactors");
                product_key5.focus();
                return false;
        }
         */
        //
        /*var obj_price_start=document.getElementById('product_prices_start');
        if(obj_price_start.value=='')
        {
            alert("{TEXT.input_price_start}");
            obj_price_start.focus();
            return false;
        }*/
        /*
        if(check_negotion.checked==true)
        {
		
                var price_sum=document.getElementById('product_price_fastener').value;
                var price_start=document.getElementById('product_prices_start').value;
                if(price_sum!=price_start)
                {
                        alert("{TEXT.price_negotion}");
                        check_negotion.focus();
                        return false;
                }
        }
         */
	
	
        frm.submit();
    }

    /*
// Created By tienhv
// Date: 14th April 2009
// The follow funtion :
// Browse through all element of function and check radio button ,
// it get value of radio button
// And return to form to submit 
     */
    function getAllValueOfRadioAndCheckboxArray(frmID){
        var form = document.getElementById(frmID);
        var formLength = form.elements.length;
        for (i=0; i<formLength; i++)
        {
            var type = form.elements[i].type;

            if (type=="radio"){
                form.elements[i].value =getCheckedValue(form.elements[i]);
            }
            if (type=="checkbox")
                if(form.elements[i].checked)
            {
                form.elements[i].value = "1";
            }
            else
            {
                form.elements[i].value = "0";
                //alert(form.elements[i].name+" value "+form.elements[i].value);
            }
					
				
        }
		
    }
    /*
// Created By tienhv
// Date: 14th April 2009
// The follow funtion :
// it get value  each radio button
     */
    function getCheckedValue(radioObj) {
        if(!radioObj)
            return 0;
        var radioLength = radioObj.length;
        if(radioLength == undefined)
            if(radioObj.checked)
                return radioObj.value;
        else
            return 0;
        for(var i = 0; i < radioLength; i++) {
            if(radioObj[i].checked) {
                return radioObj[i].value;
            }
        }
        return 0;
    }
    function setCheckedRadio(radioObj,valueCompare){
        var radioLength = radioObj.length;
        /*	alert(radioObj.type);
        if(radioLength == undefined) return;
        for(var z = 0; z < radioLength; z++)*/
        if(parseInt(radioObj.value) == parseInt(valueCompare)) {
            radioObj.checked = 'checked' ;
            //break;
        }
    }
    function checkEmptyForm(frmID){
        var form = document.getElementById(frmID);
        for (i = 0; i < form.elements.length; i++) {
            if (form.elements[i].type == "text" && form.elements[i].value == "" && (form.elements[i].readonly != 'readonly' || form.elements[i].readonly == false || form.elements[i].disabled == ''  )){
                alert("Please fill out all fields.")
                form.elements[i].focus();
                form.elements[i].style.background ="#FFFFCC";
                form.elements[i].onkeypress  = function(){
                    form.elements[i].style.background ="#FFFFFF";
                };
                return false;
            }
        }
        return true;
    }
    function selectedValueOfSelectbox(selectBox_id, valueCompare){
        if(document.getElementById(selectBox_id)){
            var selectBoxK = document.getElementById(selectBox_id);
            var selectBoxLength_k = selectBoxK.length;
            if(selectBoxLength_k>0)
                for (var k =0; k<selectBoxLength_k; k++)
                    if(selectBoxK.options[k].value == valueCompare)
            {
                selectBoxK.selectedIndex = k;
                break;
            }
        }
    }

    function filterProduct(formId){
        if(!checkEmptyForm(formId))
            return false;
        var form = document.getElementById(formId);
        ajax_filterProduct(form.fromDate.value,form.toDate.value);
    }
    function ajax_filterProduct(fromDate,toDate){
	
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" )
        {
            var myQuery = '&fromDate='+fromDate+'&toDate='+toDate;
            orderPost( oXMLHttp, "?sMod=product_index&sAction=filterProduct", myQuery, HTTPShow_ListProduct, true );
        }
    }
    function HTTPShow_ListProduct()
    {
        if ( typeof(oXMLHttp)==='undefined' )
            return;
							  
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                {
                    /*-------------------------------------------------------------------------------------------------------------------------------*/
                    if ( oJson['BODY']['RES'] != null )
                    {
                        var respontext= oJson['BODY']['RES'];
                        display(respontext,'listProduct');
                        popup.close('loading');
                    }
                    /*-------------------------------------------------------------------------------------------------------------------------------*/
                }
            }
            //	display("",'ajax_loading');
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
    }
    function check_count_image(pictures_id){
        if(parseInt(count_image)<3){
		
            var product_id = document.getElementById('product_id').value;
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
            if ( oXMLHttp && setRequest!="undefined" ){
                var myQuery = '&pictures_id='+pictures_id+'&product_id='+product_id;
                orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=upDateListImage", myQuery, HTTPShow_ListImageP, true );
            }
        } else {
            alert("{JS_TEXT.canotuploadImage}");
            return false;
        }
    }
    function HTTPShow_ListImageP()
    {
        if ( typeof(oXMLHttp)==='undefined' )
            return;
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                {
                    /*-------------------------------------------------------------------------------------------------------------------------------*/
                    if ( oJson['BODY']['RES'] != null )
                    {
                        var respontext= oJson['BODY']['RES'];
                        display(respontext,'exist_current_image');
                        count_image= parseInt(oJson['BODY']['count_image']);
                        popup.close('loading');
                    }
                    /*-------------------------------------------------------------------------------------------------------------------------------*/
                }
            }
            //	display("",'ajax_loading');
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
    }
    function remove_image_item_product(pictures_id,product_id_fieldtext,pictures_file_name){
        var product_id = document.getElementById(product_id_fieldtext).value;
        if(Trim(product_id)=='')
            alert("Not found product id");
        else {// call ajax
			
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
            if ( oXMLHttp && setRequest!="undefined" ){
                var myQuery = '&pictures_id='+pictures_id+'&product_id='+product_id+'&pictures_file_name='+pictures_file_name;
                orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=deleteImageList", myQuery, HTTPShow_ListImageP, true );
            }
        }

    }
    function ajax_upload_image(formID){
        var form = document.getElementById(formID);
        var product_id = document.getElementById("product_id").value;
        if(Trim(product_id)=='')
            alert("Not found product id");
        else {// call ajax
            var pictures_file_name = form.pictures_file_name.value;
            var pictures_comment = form.pictures_comment.value;
            var pictures_title = form.pictures_title.value;
            var pictures_note = form.pictures_note.value;
			
            oXMLHttp = checkXMLHTTP();
            var setRequest = typeof(oXMLHttp.setRequestHeader);
            if ( oXMLHttp && setRequest!="undefined" ){
                var myQuery = '&pictures_file_name='+pictures_file_name+'&pictures_comment='+pictures_comment+'&pictures_title='+pictures_title;
                myQuery += '&pictures_note='+pictures_note;
                orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=exe_upload_image", myQuery, HTTPShow_All_image, true );
            }
        }

    }
    function HTTPShow_All_image(){
        if ( typeof(oXMLHttp)==='undefined' )
            return;
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
								
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                {
                    /*-------------------------------------------------------------------------------------------------------------------------------*/
                    if ( oJson['BODY']['RES'] != null )
                    {
                        var respontext= oJson['BODY']['RES'];
                        display(respontext,'PRODUCT_EXIST_MAIN');
                        popup.close('loading');
                    }
                    /*-------------------------------------------------------------------------------------------------------------------------------*/
                }
            }
            //	display("",'ajax_loading');
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
	
    }
    function check_empty_image(formID){
        var form = document.getElementById(formID);
        if(form.pictures_file_name.value=='')
        {
            display("Empty Field!",'error_empty_file');
            form.pictures_file_name.focus();
            return false;
        }
        form.submit();
    }
    function none_error(div_id){
        display("",div_id);
    }
    function executeSearchProductList(and_or,frmID){
        var form = document.getElementById(frmID);
        var pictures_title 		= form .pictures_title_txt.value;
        var pictures_file_name	= form .pictures_file_txt.value;
        var pictures_note		= form .pictures_note_txt.value;
        //call ajax
		
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" ){
            var myQuery = '&pictures_file_name='+pictures_file_name+'&pictures_title='+pictures_title;
            myQuery += '&pictures_note='+pictures_note+'&and_or='+and_or;
            orderPost( oXMLHttp, "?sMod=upload_image_product&sAction=filter_image", myQuery, HTTPShow_Filter_Image, true );
        }
	
    }
    function HTTPShow_Filter_Image(){
        if ( typeof(oXMLHttp)==='undefined' )
            return;
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                {
                    /*-----------------------------------------------------------------------------------*/
                    if ( oJson['BODY']['RES'] != null )
                    {
                        var respontext= oJson['BODY']['RES'];
                        display(respontext,'PRODUCT_EXIST_MAIN');
                        popup.close('loading');
                    }
                    /*-------------------------------------------------------------------------------------*/
                }
            }
            //	display("",'ajax_loading');
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
    }
    function check_enter_key_ajaxInfor(e,obj){
        var ASCII_Code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;	
        var char = eval("String.fromCharCode("+ASCII_Code+")") ;
        if (ASCII_Code != 13)
        {
            // nothing to do
        }else {
            var sAction = document.getElementById('sAction').value;
            if(sAction=='do_edit')
                ajax_Load_Infor(obj.value);
						
        }
                    
    }
    function ajax_Load_Infor(product_id){
	
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" )
        {
            product_id = Trim(product_id);
            if(product_id==''){
                display("{TEXT.input_product_id}",'empty_prioduct_id');
                popup.close('loading');
                return false;
            }
            var myQuery = '&product_id='+product_id;
            orderPost( oXMLHttp, "?sMod=product_index&sAction=AJAX_GET_INFOR", myQuery, HTTP_Result_bind_data, true );
        }
    }
    function HTTP_Result_bind_data(){
        if ( typeof(oXMLHttp)==='undefined' )
            return;
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
				   
                sRes = ((oXMLHttp.responseText));
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                {
                    if ( oJson['BODY']['RES'] != null )
                    {
							 
                        /**********************/
                        fill_data_to_form(oJson['BODY'], 'frmNewProduct');// fill data to form element
                        var image_string_special= oJson['BODY']['image_string_special'];	 // Show image
                        display(image_string_special,'ELEMENT_TO_PRINT_IMAGE');
                        /*
                         *
                         * Other method transport
                         */
                        var other_method_trans= oJson['BODY']['string'];// Show OMoT1
                        insertTbody('other_method_body',other_method_trans);// use prototype
                        // remove all row had and insert result before closing tag of tbody
                        // I lost 2day to found 3 lines code
                        if(isArray(oJson['innerData'])){
                            var l= oJson['innerData'].length;
                            for(var y=0; y<l;y++){
                                // set inner after we have another data ;
                                setInnerHTMLForTdSwich(parseInt(oJson['innerData'][y][0]),oJson['innerData'][y][1],oJson['innerData'][y][2],oJson['innerData'][y][3]);
                            }
										
                        }
						
								
                        /*Set tab html or tab normal*/
                        //var product_description_normal_v = document.getElementById('product_description_normal').value;
                        //							if(parseInt(oJson['BODY']['product_description_normal']) == parseInt(product_description_normal_v))
                        //if(product_description_normal_v==1)
                        //setTabInitialize_Edit('tabber_Enter_normal','tabber_Enter_HTML_tag',0,1);// normal here
                        //else
                        //setTabInitialize_Edit('tabber_Enter_HTML_tag','tabber_Enter_normal',1,0);// html here
	
                        /*Tab mobile description */
                        if(parseInt(oJson['BODY']['product_description_swich']) == 1 )
                        {
                            change_tab('mobile_version_des_div_disable','mobile_version_des_div_enable');// also display
                            document.getElementById('product_description_on_mobile_unactive').value=oJson['BODY']['product_description_on_mobile_unactive'];
                        }
                        else
                            change_tab('mobile_version_des_div_enable','mobile_version_des_div_disable');// other show
                        /*Tab payment*/
						
                        //if(parseInt(oJson['BODY']['product_payment_method']) == 1 )
                        //								enableOrDisableDivTag('bank_name_div'); else enableOrDisableDivTag('bank_name_div');
                        enableOrDisableDivTag('set_link_to_price_list_page');
                        /**********************/
                        //DISPLAY ATTRIBUTE
                        //		 if(oJson['att_pro']!=null)
                        //							 {
                        //							 	var re=(oJson['att_pro']);
                        //
                        //
                        //								var arr_lenght=re.length;
                        //								for(var i=0;i<arr_lenght;i++)
                        //								{
                        //									var obj_att_check=document.getElementById('parent_att_'+re[i]);
                        //									if ( typeof( obj_att_check ) === 'object' )
                        //									{
                        //										obj_att_chgchecked=true;
                        //									}
                        //								}
                        //							 }
                        //DISPLAY PATH CATEGORY
                        if(oJson['path_cat']!=null)
                        {
                            var path=oJson['path_cat'];
                            display(path,'path_category');
                        }
                        //DISPLAY PRODUCT BANK
                        if(oJson['bank_name_div']!=null)
                        {
                            var bank_name_div= oJson['bank_name_div'];
                            display(bank_name_div,'bank_name_div');
                            document.getElementById('bank_name_div').style.display='block';
                        }
                        //DISPLAY Other payment
                        if(oJson['other_payment_div']!=null)
                        {
                            var other_payment_div= oJson['other_payment_div'];
                            display(other_payment_div,'other_payment_div');
                        }
                    }
                    else
                        alert('{TEXT.alert_not_found_product_id}');
                    document.getElementById('sAction').value='do_edit';
                    document.getElementById('pictures_product_id').value = oJson['BODY']['product_id'];
                    popup.close('loading');
                }
            }
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
		
    }
    function insertTbody(tbodyId,content) {
        var Parent = document.getElementById(tbodyId);
        while(Parent.hasChildNodes())
        {
            Parent.removeChild(Parent.firstChild);
        }

        new Insertion.Bottom(Parent,content);
        //	alert(child);
        // new Insertion.After(child,content);
        //chtblild.remove(child);
    }
    function ajax_Load_Infor_Image(product_id){
	
        oXMLHttp_Image = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp_Image.setRequestHeader);
        if ( oXMLHttp_Image && setRequest!="undefined" )
        {
            product_id = Trim(product_id);
            if(product_id=='')	return false;
            var myQuery = '&product_id='+product_id;
            orderPost( oXMLHttp_Image, "?sMod=product_index&sAction=AJAX_RELOAD_IMAGE", myQuery, HTTP_Result_bind_data_image, true );
        }
    }
    function HTTP_Result_bind_data_image(){
        if ( typeof(oXMLHttp_Image)==='undefined' )
            return;
        // Return status of XMLHttp object
        if ( oXMLHttp_Image.readyState==4 )
        {
            // if oXMLHttp_Image.status is OK
            if ( oXMLHttp_Image.status==200 )
            {
				   
                sRes = ((oXMLHttp_Image.responseText));
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                    if ( oJson['BODY']['RES'] != null )
                {
                    var respontext= oJson['BODY']['RES'];
                    display(respontext,'ELEMENT_TO_PRINT_IMAGE');
                    popup.close('loading');
                }
            }
            if ( oXMLHttp_Image.status==404)
                alert("Page not found");
        }
		
    }
    /*
     * Created by: Tienhv
     * Date : 19th April 2009;
     */
    function fill_data_to_form(array_data,formID){
        var form = document.getElementById(formID);
        var name_e,selectBox_id,valueCompare;
        var type_e ;
        for (i = 0; i < form.elements.length; i++) {
            type_e = form.elements[i].type;
            // fill data to textbox
            if (type_e == "text" || type_e == "hidden"){
                name_e = form.elements[i].name;
                form.elements[i].value = array_data[name_e];
            }
            // fill data to select-one
            if (type_e == "select-one" ){
                name_e = form.elements[i].name;
                selectBox_id = form.elements[i].id;
                valueCompare = array_data[name_e];
                selectedValueOfSelectbox(selectBox_id,valueCompare);
            }
            /*
// fill data to checkbox
             */
            if (type_e == "checkbox" ){
                name_e = form.elements[i].name;
                if(parseInt(array_data[name_e]) ==1)
                    form.elements[i].checked = 'checked';
                else
                    form.elements[i].checked = '';
            }
            /*
// fill data to radio
             */
            if (type_e=="radio"){
                name_e = form.elements[i].name;
                setCheckedRadio(form.elements[i],array_data[name_e]);
            }
            /*
// fill data to radio
             */
            if (type_e=="textarea"){
                name_e = form.elements[i].name;
                if(name_e!="product_description_on_mobile_unactive") // exception
                    if(name_e == "product_description_html_tag") // exception
                        form.elements[i].value= array_data['product_description'];
                else
                {
                    tinyMCE.get(name_e).setContent(array_data[name_e]);
                    //form.elements[i].value= array_data[name_e];
                }
							
            }
        }	// End for
    }// End function

    function back_to_edit_page(){
        var frm = document.getElementById('back_to_edit_page_frm');
        if(frm.id == '' )
            alert("Not found!\nProduct id is missing.");
        else frm.submit();
    }
    function check_length(input_textbox,swichText){
    	
        var input_e = document.getElementById(input_textbox);
        var value_to_check =Trim(input_e.value);
        var swich = swichText.substring(0,swichText.length-1);//Syntax: string.substring(start, stop);
        if(value_to_check !=''){
            if(swich == 'other_link_to_price_list_')
            {
                //If you want foucus on IE
                // You must remember a thing
                // Text box which you want to focus need show before call focus();
                popup.open("popup_set_link");
                bindData(swichText,'cache_data_to_OMT');
            }else
            {
                popup.open("set_uniform_national");
                bindData_2(swichText,'cache_data_to_OMT_2')
            }
		
        }else{
            input_e.focus();
            input_e.value='';
        }
    }
    function check_length_defaul(input_textbox,swichText){
        var input_e = document.getElementById(input_textbox);
        var value_to_check =Trim(input_e.value);
        var swich = swichText.substring(0,swichText.length);//Syntax: string.substring(start, stop);
        if(value_to_check !=''){
        	alert(swich);
            if(swich == 'other_link_to_price_list')
            {
                //If you want foucus on IE
                // You must remember a thing
                // Text box which you want to focus need show before call focus();
                popup.open("popup_set_link");
                bindData(swichText,'cache_data_to_OMT');
            }else
            {
                popup.open("set_uniform_national");
                bindData_2(swichText,'cache_data_to_OMT_2')
            }
		
        }else{
            input_e.focus();
            input_e.value='';
        }
    }
    function bindData_2(source,destination){
        //alert(source);alert(destination);
        var frm = document.getElementById(destination);
        var source_value = document.getElementById(source).value;
        frm.cache_other_uniform_price.focus();
        frm.cache_other_uniform_price.value = source_value;
        frm.swichText.value = source;
    }
    function bindData(source,destination){
        var frm = document.getElementById(destination);
        var source_value = document.getElementById(source).value;
        //	document.getElementById('cache_other_link_id').focus();
        frm.cache_other_link.focus();
        //If you want foucus on IE
        // You must remember a thing
        // Text box which you want to focus need show before call focus();
        frm.cache_other_link.value = source_value;
        frm.swichText.value = source;
    }
    function rebindData(source,divId){
        //alert("fffffffff");
        var frm = document.getElementById(source);
        var url = frm.cache_other_link.value;
        if(!CheckValidUrl(url)){
            frm.cache_other_link.focus();
            document.getElementById('url_invalid').style.display ='block';
        }else{
            var cache_to_getId = frm.swichText.value;
            // cache to get td_id
            var id = cache_to_getId.substring(cache_to_getId.length-1,cache_to_getId.length);
            id= parseInt(id);
            //var id=1
            if(id==0)
                id=10;
            td_id = getTdId(id);
            setInnerHTMLForTdSwich(1,td_id,url,id);
            document.getElementById(frm.swichText.value).value = url;
            popup.close(divId);
            document.getElementById('one_more_other_button').focus();
        }
    }
    function rebindData_defaul(source,divId){
        //alert("fffffffff");
        var frm = document.getElementById(source);
        var url = frm.cache_other_link.value;
        if(!CheckValidUrl(url)){
            frm.cache_other_link.focus();
            document.getElementById('url_invalid').style.display ='block';
        }else{
            var cache_to_getId = frm.swichText.value;
            // cache to get td_id
            var id = cache_to_getId.substring(cache_to_getId.length-1,cache_to_getId.length);
            id= parseInt(id);
            var id=1;
            if(id==0)
                id=10;
            td_id = getTdId(id);
            setInnerHTMLForTdSwich(1,td_id,url,id);
            document.getElementById(frm.swichText.value).value = url;
            popup.close(divId);
            document.getElementById('one_more_other_button').focus();
        }
    }
    function rebindData_2(source,divId){
        //alert("test");
        var frm = document.getElementById(source);
        var value = frm.cache_other_uniform_price.value;
        if(!check_Number(value) || (value=='')){
            frm.cache_other_uniform_price.focus();
            document.getElementById('number_invalid').style.display ='block';
        }else{
            var cache_to_getId = frm.swichText.value;
            // cache to get td_id
            var id = cache_to_getId.substring(cache_to_getId.length-1,cache_to_getId.length);
            id= parseInt(id);
            if(id==0)
                id=10;
            td_id = getTdId(id);
            setInnerHTMLForTdSwich(2,td_id,value,id);
            document.getElementById(frm.swichText.value).value = value;
			
            //rebindInnerHTMLOfTd();
            popup.close(divId);
        }
    }
    function rebindData_2_defaul(source,divId){
        //alert("test");
        var frm = document.getElementById(source);
        var value = frm.cache_other_uniform_price.value;
        if(!check_Number(value) || (value=='')){
            frm.cache_other_uniform_price.focus();
            document.getElementById('number_invalid').style.display ='block';
        }else{
            var cache_to_getId = frm.swichText.value;
            // cache to get td_id
            var id = 1;//cache_to_getId.substring(cache_to_getId.length-1,cache_to_getId.length);
            id= parseInt(id);
            if(id==0)
                id=10;
            td_id = getTdId(id);
            setInnerHTMLForTdSwich(2,td_id,value,id);
            document.getElementById(frm.swichText.value).value = value;
            var frm1 =	document.getElementById("frmNewProduct");
            //document.getElementById("other_uniform_price").value=value;
            //$("other_uniform_price").innerHTML = value;
            //alert(swichText);
            //alert(frm.swichText.value);
            //rebindInnerHTMLOfTd();
            document.getElementById('other_uniform_price').value="The Value Here"
            //alert(document.getElementById('other_uniform_price').value);
            //popup.close(divId);
        }
    }
    function setInnerHTMLForTdSwich(swich,tdId,valueShow,id){
        var objTd= document.getElementById(tdId);
        objTd.innerHTML ='';// clear text
        var link_del = addLink('','javascript: removeAndSetInitialize(\''+tdId+'\',\''+id+'\');','javascript: removeAndSetInitialize(\''+tdId+'\',\''+id+'\');',"{JS_TEXT.remove} ");
        var link_edit='';
        var links;
        if(swich==1){
            var text1 = addElementHTML('font','','','#333333',textS1 ) ;
            var link_o = addLink('',valueShow,'',"{JS_TEXT.testLink} ",'_blank');
            link_edit = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');',"{JS_TEXT.Edit} ");
            links = new Array(text1,link_o,slash,link_edit,slash,link_del);
        }else{
			
			
            var text1 = addElementHTML('font','','','#333333',textS2_1 ) ;
            var text_mid = addElementHTML('font','','','#333333',valueShow ) ;
            var text2 = addElementHTML('font','','','#333333',textS2_2 ) ;
            link_edit = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');',"{JS_TEXT.Edit} ");
            links = new Array(text1,slash,text_mid,slash,text2,link_edit,slash,link_del);
        }
        for(var j=0; j<links.length;j++)
            if(typeof(links[j]) === "object"){// is element html
                if( isArray(links[j]) )
                    for(var m=0; m<links[j].length; m++)
                        if(typeof(links[j][m]) === "object")
                            myTD.appendChild(links[j][m]);
                else
                    objTd.innerHTML	+=links[j][m];
                else   objTd.appendChild(links[j]);
						   
                //myTD.innerHTML=(array_value[j]);
            }else
            objTd.appendChild(document.createTextNode(links[j]));
	
    }
    function removeAndSetInitialize(tdId,id){
        var objTd= document.getElementById(tdId);
        objTd.innerHTML ='';// clear text
        var count_row = checkRows('other_method_trans_tbl');
        <!--Set for hidden-->
        var other_link_to_price_list_i = document.getElementById("other_link_to_price_list_" +id);
        var other_uniform_price_i = document.getElementById("other_uniform_price_" +id);
        other_link_to_price_list_i.value ='';
        other_uniform_price_i.value ='';
        var link_o = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_link_to_price_list_'+id+'\');',"{JS_TEXT.textPTPL} ");
        var link_2 = addLink('','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');','javascript: check_length(\'other_title_textbox_'+id+'\',\'other_uniform_price_'+id+'\');',"{JS_TEXT.setunif} ");
        var links = new Array(link_o,slash,link_2);
        for(var j=0; j<links.length;j++)
            if(typeof(links[j]) === "object"){// is element html
                if( isArray(links[j]) )
                    for(var m=0; m<links[j].length; m++)
                        if(typeof(links[j][m]) === "object")
                            myTD.appendChild(links[j][m]);
                else
                    objTd.innerHTML	+=links[j][m];
                else   objTd.appendChild(links[j]);
							   
                //myTD.innerHTML=(array_value[j]);
            }else
            objTd.appendChild(document.createTextNode(links[j]));
			
    }
    function getTdId(order){
        return "td2_"+order;
    }
    /*
     *Created by: tienhv ;
     * Date: 26th April;
     */
    function add_one_more_other_div(){
        var div_cover = document.getElementById('other_method_transport');
        var current_innerHTML = div_cover.innerHTML;
        var current_length = div_cover.childNodes.length;
        var type_node= '';
        var y=1;
        if (div_cover.childNodes && current_length > 0)
            for (var x = 0; x < current_length; x++)
            //		alert(typeof(div_cover.childNodes[x]))	;
                alert(div_cover.childNodes[x].type)	;
        if(div_cover.childNodes[x].type ="text")
        {
            alert(div_cover.childNodes[x].name);
        }


    }

    function AddEndRow(tid,countCell,array_value) {//tbody id, count(cell)+value to add
        // first we create <tr> element
        var  arr_length = array_value.length;
        var j;
        var myTR=document.createElement('tr');
        var myTD_arr = new Array();
        // now we create first cell (<td> element)
        if(countCell>0 && arr_length>0 )
            for(j=0; j< countCell;j++)
        {
            var myTD=null;
            myTD=document.createElement('td');
            // check the value of array value is text box or normal text
            // Upgraded by : TienHV
            // Date : 27th April*
            if(typeof(array_value[j]) === "object"){// is element html
                if( isArray(array_value[j]) )
                    for(var m=0; m<array_value[j].length; m++)
                        if(typeof(array_value[j][m]) === "object")
                {
                    myTD.appendChild(array_value[j][m]);
                }else
                    myTD.innerHTML	+=array_value[j][m];
                else   myTD.appendChild(array_value[j]);
						   
                //myTD.innerHTML=(array_value[j]);
            }else
                myTD.appendChild(document.createTextNode(array_value[j]));
		
            myTD_arr[j] = myTD;
            myTR.appendChild(myTD);
        }
        // after that we add our row (tr) to tbody
        document.getElementById(tid).appendChild(myTR);
        return new Array(myTR,myTD_arr);
    }


	  
    function addOtherMethodTrans(obj_btt){// is Combo
        var count_row = checkRows('other_method_trans_tbl');
        if(count_row==10)
            obj_btt.disabled="disabled"	;
        else obj_btt.disabled="";
        var order = count_row+1;
        var textBoxOther_i = addTextbox("other_title_textbox_" +order,"other_title_"+order,"",40,15);
        var other_link_to_price_list_i = addHiddenElement("hidden","other_link_to_price_list_" +order,"other_link_to_price_list_"+order,"");
	
        var other_uniform_price_i = addHiddenElement("hidden","other_uniform_price_" +order,"other_uniform_price_"+order,"");
        var link_o = addLink('','javascript: check_length(\'other_title_textbox_'+order+'\',\'other_link_to_price_list_'+order+'\');','',"{JS_TEXT.textPTPL}");
        var link_2 = addLink('','javascript: check_length(\'other_title_textbox_'+order+'\',\'other_uniform_price_'+order+'\');','',"{JS_TEXT.setunif}");
        var links = new Array(link_o,slash,link_2);
        array_value_cell 	= new Array(3) ;
        array_value_cell[0]	=  new Array(3) ;
        array_value_cell[0][0]	= textBoxOther_i;
        array_value_cell[0][1]	= other_link_to_price_list_i;
        array_value_cell[0][2]	= other_uniform_price_i;
        array_value_cell[1]	=new Array(3);
        array_value_cell[1][0]	=link_o;
        array_value_cell[1][1]	="&nbsp;|&nbsp;";
        array_value_cell[1][2]	=link_2;
        array_value_cell[2] = '{FORM.remove}';
        myTR_And_Last_Td = AddEndRow('other_method_body',3,array_value_cell);// Return the tr had
        //insert And last tf of this tr
        format_CSS_for_TrInsert('other_method_trans_tbl','other_method_body',myTR_And_Last_Td);
    }
    function addOtherMethodTransDefaul(obj_btt){// is Combo
        //alert("dddddddd");
        var frm =	document.getElementById("frmNewProduct");
        //alert(frm.other_title_of_method.value);
        var count_row = checkRows('other_method_trans_tbl');
        if(count_row==10)
            obj_btt.disabled="disabled"	;
        else obj_btt.disabled="";
        var order = ""; //count_row+1;
        var textBoxOther_i = addTextbox("other_title_of_method","other_title_of_method",frm.other_title_of_method.value,40);
        var other_link_to_price_list_i = addHiddenElement("hidden","other_link_to_price_list","other_link_to_price_list",frm.other_link_to_price_list.value);
	
        var other_uniform_price_i = addHiddenElement("hidden","other_uniform_price","other_uniform_price",frm.other_uniform_price.value);
        var link_o = addLink('','javascript: check_length_defaul(\'other_title_of_method'+order+'\',\'other_link_to_price_list'+order+'\');','javascript: check_length_defaul(\'other_title_of_method'+order+'\',\'other_link_to_price_list'+order+'\');',"{JS_TEXT.textPTPL}");
        var link_2 = addLink('','javascript: check_length_defaul(\'other_title_of_method'+order+'\',\'other_uniform_price'+order+'\');','javascript: check_length_defaul(\'other_title_of_method'+order+'\',\'other_uniform_price'+order+'\');',"{JS_TEXT.setunif}");
        var links = new Array(link_o,slash,link_2);
        array_value_cell 	= new Array(3) ;
        array_value_cell[0]	=  new Array(3) ;
        array_value_cell[0][0]	= textBoxOther_i;
        array_value_cell[0][1]	= other_link_to_price_list_i;
        array_value_cell[0][2]	= other_uniform_price_i;
        array_value_cell[1]	=new Array(3);
        array_value_cell[1][0]	=link_o;
        array_value_cell[1][1]	="&nbsp;|&nbsp;";
        array_value_cell[1][2]	=link_2;
        array_value_cell[2] = '{FORM.remove}';
        myTR_And_Last_Td = AddEndRow('other_method_body',3,array_value_cell);// Return the tr had
        //insert And last tf of this tr
        format_CSS_for_TrInsert('other_method_trans_tbl','other_method_body',myTR_And_Last_Td);
    }
    function remove_this_row(tblId,tbody,tr_id){
        var count_row = checkRows(tblId);
        obj_btt= document.getElementById('one_more_other_button');
        if(typeof(obj_btt) === "object")
            if(count_row==10)
                obj_btt.disabled="disabled"	;
        else obj_btt.disabled="";
        MoveItem(tbody,tr_id);
    }
    function MoveItem(tbody,tr_id)
    {
        var myTbl=document.getElementById(tbody);
        //var deltr=myTbl.lastChild;
        var deltr = document.getElementById(tr_id);
        while (deltr.nodeType==3)
        { myTbl.removeChild(deltr);
 
            deltr=myTbl.lastChild;
        }
        myTbl.removeChild(deltr);
    }


    function format_CSS_for_TrInsert(table_id,tbody_id,myTR_And_Last_Td){
        // check even number
        /*	if(checkRows(table_id)%2)// neu so luong ban ghi hien tai la chan
                        myTR_And_Last_Td[0].className ="class_tr_insert_if_even_number";// ban ghi se them co class cua so le
                 else myTR_And_Last_Td[0].className ="class_tr_insert_odd_number"; */
        var current_tr = checkRows(table_id);
        myTR_And_Last_Td[0].className ="td1";
        // Thiet lap id cho tr
        myTR_And_Last_Td[0].id ='tr_other_'+current_tr;
        //myTR_And_Last_Td[0].style.width = "";
		
        myTR_And_Last_Td[1][2].style.cursor = "pointer";
        myTR_And_Last_Td[1][1].style.color = "#009900";
        myTR_And_Last_Td[1][1].id = 'td2_'+current_tr;
        myTR_And_Last_Td[1][2].title = "{JS_TEXT.removeRow}";
        /*		myTR_And_Last_Td[1][1].id		    = "td_one_"+id;
                myTR_And_Last_Td[1][2].id		    = "td_two_"+id;*/
        /*		myTR_And_Last_Td[1][0].style.width = "55%";
                myTR_And_Last_Td[1][1].style.width = "15%";
                myTR_And_Last_Td[1][2].style.width = "17%";*/
	   
        // set su kien onclick cho tr va td
        /*	  	myTR_And_Last_Td[1][3].onclick  = function(){
                        remove_this_product_out_list(tbody_id,id);
                }*/
        myTR_And_Last_Td[1][2].onclick  = function(){
            remove_this_row('other_method_trans_tbl','other_method_body',myTR_And_Last_Td[0].id)
        }
        /*	 myTR_And_Last_Td[0].onclick  = function(){
                ajax_load_picture(id);
                }*/// function cho tr
    }

    function round(number,X) {//
        // rounds number to X decimal places, defaults to 2
        X = (!X ? 2 : X);
        return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
    }
    function checkRows(table_id)  {
        var tbl=document.getElementById(table_id);
        return (tbl.rows.length);
        //   for (var i=0; i<tbl.rows.length; i++)
    }
    function addTextbox(ID,name,value,size,maxlength) {
        //All atrribute must be lowercase before set attribute
        // Because IE detect attribute by chu thuong
        var textbox = document.createElement("input");
        textbox.setAttribute("type",'text');
        textbox.setAttribute("id",ID);
        textbox.setAttribute("name", name);
        //tb.setAttribute("value", tb.getAttribute("ID"));
        textbox.setAttribute("value", value);
        textbox.setAttribute("size", size);
        textbox.setAttribute("maxlength", maxlength);
        return textbox;
        //document.getElementById("container").appendChild(tb);
    }
    function addElementForm(type,ID,name,value) {
        //var textbox = document.createElement("input");
        textbox.setAttribute("type",type);
        textbox.setAttribute("id",ID);
        textbox.setAttribute("name", name);
        //tb.setAttribute("value", tb.getAttribute("ID"));
        textbox.setAttribute("value", value);
        //	textbox.setAttribute("size", size);
        return textbox;
        //document.getElementById("container").appendChild(tb);
    }
    function addHiddenElement(type,ID,name,value) {
        var hiddenE = document.createElement("input");
        hiddenE.setAttribute("type",'hidden');
        hiddenE.setAttribute("id",ID);
        hiddenE.setAttribute("name", name);
        //tb.setAttribute("value", tb.getAttribute("ID"));
        hiddenE.setAttribute("value", value);
        //	textbox.setAttribute("size", size);
        return hiddenE;
        //document.getElementById("container").appendChild(tb);
    }
    function addElementHTML(tag,ID,name,color,value) {
        var ele = document.createElement(tag);
        ele.setAttribute("id",ID);
        ele.setAttribute("name", name);
        ele.setAttribute("color", color);
        ele.appendChild(document.createTextNode(value));
        //	ele.setAttribute("value", value);
        return ele;
    }
    function addLink(name,href,onclick,text,target) {
        var links = document.createElement('a');
        links.setAttribute('name', name);
        links.setAttribute('href', href);
        links.setAttribute('onclick',onclick );
        if(typeof(target) === 'undefined'){
            links.setAttribute('target','_self');
        }else
            links.setAttribute('target',target);
        links.appendChild(document.createTextNode(text));
        return links;
        //document.getElementById("container").appendChild(tb);
    }
	
    function isArray(obj) {
        if (obj == null) return false;
        return obj.constructor == Array;
    }
    function CheckValidUrl(strUrl)
    {

        var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        return RegexUrl.test(strUrl);

    }

    // Sample use

    function update_size_load_html_form(pid_textbox){
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" )
        {
            var pid = document.getElementById(pid_textbox).value;
            if(Trim(pid)=='') {	alert("ID not found"); return false;	}
            var myQuery = '&product_id='+pid;
            orderPost( oXMLHttp, "?sMod=product_index&sAction=update_size", myQuery, HTTPShowPopup_update_psize, true );
        }
    }
    function HTTPShowPopup_update_psize()
    {
        if ( typeof(oXMLHttp)==='undefined' )
            return;
							  
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
                alert(sRes);
                oJson = sRes.parseJSON();
                if ( typeof( oJson ) === 'object' )
                { if ( oJson['BODY']['RES'] != '' )
                        document.getElementById('popup_update_psize_content').innerHTML = oJson['BODY']['RES']
                    popup.open('popup_update_psize');
                }
            }
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }
                        
    }
    function setRadioValue(radioObj){
        if(radioObj.checked)
        {
            radioObj.checked='';
        }else
        {
            radioObj.checked='checked';
        }
    }
    function checkUrl(anchors,url){
        var e = document.getElementById(url);
        var vl = e.value;
        if(!CheckValidUrl(vl)){
            document.getElementById('url_invalid_2').style.display ="block";
            e.focus();
        }
        else{
            anchors.setAttribute('href','http://www.google.com.vn/search?hl=vi&q='+vl);
            s
        }
    }

    /*CHOOSE TEMPLATE*/
    function getElementsByName_iefix(tag, name) {
     
        var elem = document.getElementsByTagName(tag);
        var arr = new Array();
        for(i = 0,iarr = 0; i < elem.length; i++) {
            att = elem[i].getAttribute("name");
            if(att == name) {
                arr[iarr] = elem[i];
                iarr++;
            }
        }
        return arr;
    }

    function change_template(value){
        if(value==''){
            return false;
	}
	$.ajax({
		url: '{URL_SITE}?sMod=product_index&sAction=choose_template',
		type: 'post',
		data: {
                        template_path: value
                        },
		success: function( sResponse ) {
                    oJson = $.parseJSON(sResponse);
                    if ( typeof( oJson ) === 'object' ) {
                        var result_ex = oJson['BODY']['temp_ex'];
                        if(result_ex!='')
                        {
                            tinyMCE.get('product_explanation').setContent(result_ex);
                        }
                        var result_note=oJson['BODY']['temp_note'];
                        if(result_note!='')
                        {
                            tinyMCE.get('product_note').setContent(result_note);
                        }
                        var result_rank=oJson['BODY']['temp_rank'];
						
                        if(result_rank!='')
                        {
                            tinyMCE.get('product_rank').setContent(result_rank);
                            display(result_rank,"div_rank_temp");
                        }
                        var result_rank_dagame=oJson['BODY']['temp_rank_dagame'];
                        if(result_rank_dagame!='')
                        {
                            //tinyMCE.get('product_rank').setContent(result_rank);
                            display(result_rank_dagame,"div_rank_dagame_temp");
                        }
                        var result_size=oJson['BODY']['temp_size'];
                        if(result_size!='')
                        {
                            tinyMCE.get('product_size').setContent(result_size);
                        }
                    }
		},
		error: function(xhr, txtStatus, errorThrown) {
			alert('error ' + xhr.status + ' -- ' + xhr.statusText);
		}
	});
    }

    function change_size(value)
    {
        if(value=='')
        {
            return;
        }
	
        var obj=getElementsByName_iefix('input','product_template_id');
	
        for(var i=0;i<obj.length;i++)
        {
            if(obj[i].checked==true)
            {
                var path_temp=obj[i].value;
            }
        }
	
        oXMLHttp = checkXMLHTTP();
        var setRequest = typeof(oXMLHttp.setRequestHeader);
        if ( oXMLHttp && setRequest!="undefined" )
        {
            var myQuery = "&template_path="+path_temp+"&size_id="+value;
            orderPost( oXMLHttp, "?sMod=product_index&sAction=choose_size", myQuery, HTTPShowChooseSize, true );
        }
    }
    function HTTPShowChooseSize()
    {
        if ( typeof(oXMLHttp)==='undefined' )
            return;
        // Return status of XMLHttp object
        if ( oXMLHttp.readyState==4 )
        {
            // if oXMLHttp.status is OK
            if ( oXMLHttp.status==200 )
            {
                sRes = ((oXMLHttp.responseText));
                //oJson = sRes.parseJSON();
                oJson = $.parseJSON(sRes);
                if ( typeof( oJson ) === 'object' )
                {	
                    var result_size=oJson['BODY']['display_size'];
                    if(result_size!='')
                    {
                        tinyMCE.get('product_size').setContent(result_size);
                    }
                    popup.close('loading');
                }
            }
            if ( oXMLHttp.status==404)
            {
                alert("Page not found");
            }
        }

    }
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}

    function change_rank(value){
		if(value != 'damage'){
				var text_damage = document.getElementById('div_rank_temp').innerHTML;
				tinyMCE.get('product_rank').setContent(text_damage);
				var text = tinyMCE.get('product_rank').getContent();
				var div_rank = document.getElementById("div_rank_temp");
				display(text,"div_rank_temp");
			
				var div_rank_name=document.getElementById('rank_name');
				display(value,'rank_name');
			
				var txt_rank=div_rank.innerHTML;
				tinyMCE.get('product_rank').setContent(txt_rank);
						
        }
        else{
            var text_damage=document.getElementById('div_rank_dagame_temp').innerHTML;
            tinyMCE.get('product_rank').setContent(text_damage);
		
        }
        //display('','div_rank_temp');
    }
    function change_condition(value)
    {
		
			var text_damage=document.getElementById('div_rank_temp').innerHTML;
			
			tinyMCE.get('product_rank').setContent(text_damage);
			var text=tinyMCE.get('product_rank').getContent();
			var div_rank=document.getElementById("div_rank_temp");
			display(text,"div_rank_temp");
		
			var div_rank_name=document.getElementById('condition');
			display(value,'condition');
		
			var txt_rank=div_rank.innerHTML;
			tinyMCE.get('product_rank').setContent(txt_rank);
			//display('','div_rank_temp');
		
    }

    function add_more_bank_txtbox()
    {
        now_div_blank_id=document.getElementById('now_div_blank_id').value;
	
        if(now_div_blank_id=='')
        {
            now_div_blank_id=1;
        }
        now_div_blank_id=parseInt(now_div_blank_id);

        if(now_div_blank_id<10)
        {
            document.getElementById('div_bank_'+now_div_blank_id).style.display='block';
        }
        if(now_div_blank_id==9)
        {
            document.getElementById('btn_add_more_bank_txtbox').disabled="true";
        }
        now_div_blank_id++;
        document.getElementById('now_div_blank_id').value=now_div_blank_id;
    }
    function show_hide_div_bank(obj)
	{
		if(obj.checked==true)
		{
			document.getElementById('bank_name_div').style.display='block';
			document.getElementById('btn_add_more_bank_txtbox').disabled=false;
		}
		else
		{
			document.getElementById('now_div_blank_id').value='';
			document.getElementById('bank_name_div').style.display='none';
		}
		
		for(var i=0;i<10;i++)
		{
			document.getElementById('product_bank_'+i).value='';
			if(i==0)
			{
				document.getElementById('div_bank_'+i).style.display='block';
				document.getElementById('product_bank_'+i).value='';
			}
			else
				document.getElementById('div_bank_'+i).style.display='none';
		}
	}

    function add_more_other_payment_txtbox()
    {
        now_other_method_transfer=document.getElementById('now_other_method_transfer').value;
        //alert(now_other_method_transfer);
	
        if(now_other_method_transfer=='' || now_other_method_transfer==0)
        {
            now_other_method_transfer=1;
        }
        now_other_method_transfer=parseInt(now_other_method_transfer);
	
        if(now_other_method_transfer<10)
        {
            document.getElementById('div_other_payment_method_'+now_other_method_transfer).style.display='block';
        }
        if(now_other_method_transfer==9)
        {
            document.getElementById('btn_add_more_other_payment_txtbox').disabled="true";
        }
        now_other_method_transfer++;
        document.getElementById('now_other_method_transfer').value=now_other_method_transfer;
    }

    //Thanhbx Change Store Name
    function changeStoreName(id,store){

        var text = document.getElementById("store4").value;
        alert(text.toString());
        document.frmNewProduct.product_store.value=text+store;
    }
</script>
